#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: twl
@date: 2020/7/8 15:48
@description:
"""
import re


class ExceptionUtil(object):
	@staticmethod
	def get_error_print_log(e: Exception):
		if not e:
			return e
		msg_list = e.args
		msg = '\n'.join(msg_list)
		return msg[0:ExceptionUtil.get_index(msg)]

	@staticmethod
	def get_index(msg):
		count = 0
		size = len(msg)
		matcher = re.compile('\n')
		search = matcher.search(msg)
		if not search:
			return size
		pos = search.span()[1]
		while 0 < pos < size:
			search = matcher.search(msg, pos=pos)
			if not search:
				break
			pos = search.span()[1]
			count += 1
			if count > 2:
				break
		return pos
